package com.cjb.cloudsystem.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.cjb.cloudsecurity.mybatisHandler.FieldMetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author chenjinbin
 * @Package IntelliJ IDEA
 * @Class BatchInsertService
 */
@Configuration
@Slf4j
public class MybatisPlusConfig {

    /**
     * 分页插件。如果你不配置，分页插件将不生效
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
//        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        // 指定数据库方言为 MYSQL
//        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//        // 乐观锁
////        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//        // 防止全表更新与删除
////        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
//        return interceptor;
        MybatisPlusInterceptor plusInterceptor = new MybatisPlusInterceptor();
        log.info("执行了mysql数据库驱动");
        plusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return plusInterceptor;
    }

    /**
       *
       * 增加注入时间与修改角色的操作
       * @param
       * @return
       * @author chenjinbin
       * @email 2213859123@qq.com
       * @date 2023-07-12 9:10
       */
    @Bean
    public FieldMetaObjectHandler fieldMetaObjectHandler(){
        return new FieldMetaObjectHandler();
    }

}
